﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExcelToXml
{
    class basic
    {
        public void  XML()
        {
            #region 111
            //XmlSerializer formatter = new XmlSerializer(str.GetType());
            //using (MemoryStream memory = new MemoryStream())
            //using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memory, Encoding.UTF8))
            //{
            //    formatter.Serialize(xmlTextWriter, str);
            //    using (MemoryStream mem2 = (MemoryStream)xmlTextWriter.BaseStream)
            //    {
            //        string ret = Encoding.UTF8.GetString(mem2.ToArray());
            //        MessageBox.Show(ret);
            //        //string result = @"<a><b><c>asdfsdf</c></b></a>";
            //        XmlDocument xmlDoc = new XmlDocument(); 
            //        StreamWriter sw=new StreamWriter(
            //       // xmlDoc.LoadXml(ret);
            //        xmlDoc.Save("D:\\2.xml");
            //    }
            //}

            //字符串转化xml保存
            //XmlDocument xmlDoc = new XmlDocument();            
            //string result = @"<a><b><c>asdfsdf</c></b></a>";
            //xmlDoc.LoadXml(result);
            //xmlDoc.Save("D:\\1.xml");


            //  设置，添加节点

            //XmlDocument xmlDoc = new XmlDocument();
            //XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null);
            //xmlDoc.AppendChild(dec);
            ////创建一个根节点（一级）
            //XmlElement root = xmlDoc.CreateElement("First");
            //xmlDoc.AppendChild(root);

            //XmlElement xe1 = xmlDoc.CreateElement("book");//创建一个节点 
            //xe1.SetAttribute("genre", "李赞红");//设置该节点genre属性 
            //xe1.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
            //XmlElement xesub1 = xmlDoc.CreateElement("title");
            //xesub1.InnerText = "CS从入门到精通";//设置文本节点 
            //xe1.AppendChild(xesub1);//添加到节点中 
            //XmlElement xesub2 = xmlDoc.CreateElement("author");
            //xesub2.InnerText = "候捷";
            //xe1.AppendChild(xesub2);
            //XmlElement xesub3 = xmlDoc.CreateElement("price");
            //xesub3.InnerText = "58.3";
            //xe1.AppendChild(xesub3);
            //root.AppendChild(xe1);//
            //xmlDoc.Save("D:\\bookstore.xml");
            #endregion 
        }



    }
}
